package class41To50;

import java.io.*;
import java.util.HashMap;

public class LongestSubarraySumEqualsAim {

    public static int MAX_N = 1000005;

    public static int sum;

    public static int aim;

    public static int n;

    public static int[] arr = new int[MAX_N];

    public static int ans;

    public static HashMap<Integer, Integer> map = new HashMap<>();


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            in.nextToken();
            //aim = (int) in.nval;
            aim = 0;
            for (int i = 0; i < n; i++) {
                in.nextToken();
                int x = (int) in.nval;
                if (x > 0) {
                    arr[i] = 1;
                } else if (x < 0) {
                    arr[i] = -1;
                } else {
                    arr[i] = 0;
                }
            }
            computerRet();
            out.println(ans);
        }
        out.flush();
        out.close();
        br.close();
    }

    private static void computerRet() {
        map.clear();
        sum = 0;
        ans = 0;
        map.put(0, -1);
        for (int i = 0; i < n; i++) {
            sum += arr[i];
            if (map.containsKey(sum - aim)) {
                ans = Math.max(ans, i - map.get(sum - aim));
            }
            if (!map.containsKey(sum)) {
                map.put(sum, i);
            }
        }
    }
}
